SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[DISC_DistProductsUpdate]
	@DistID varchar(50),
	@PermID varchar(50),
	@SKU nvarchar(50),
	@ListPrice decimal(18,2),
	@ACSResourceID varchar(50),
	@DRMType varchar(20),
	@FileName nvarchar(255),
	@FileSize int,
	@MaxDownloads int
AS
BEGIN
	SET NOCOUNT ON;

	IF (EXISTS(SELECT [ID] FROM DISC_DistProducts WHERE DistID = @DistID AND PermID = @PermID)) BEGIN
		-- Update record
		UPDATE DISC_DistProducts
		SET
			SKU = @SKU,
			ListPrice = @ListPrice,
			ACSResourceID = @ACSResourceID,
			DRMType = @DRMType,
			[FileName] = @FileName,
			FileSize = @FileSize,
			MaxDownloads = @MaxDownloads
		WHERE DistID = @DistID AND PermID = @PermID
	END
	ELSE BEGIN
		-- Insert record
		INSERT INTO DISC_DistProducts
		(
			DistID,
			PermID,
			SKU,
			ListPrice,
			ACSResourceID,
			DRMType,
			[FileName],
			FileSize,
			MaxDownloads
		)
		VALUES
		(
			@DistID,
			@PermID,
			@SKU,
			@ListPrice,
			@ACSResourceID,
			@DRMType,
			@FileName,
			@FileSize,
			@MaxDownloads
		)
	END
END
GO
